package com.icarsaas.saas.master.utils;

import cn.hutool.db.ds.simple.SimpleDataSource;
import com.icarsaas.saas.common.utils.SpringContextUtil;
import com.icarsaas.saas.master.config.MasterDatabaseConfigProperties;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * @author xrong120@gmail.com
 * @title: MasterDbUtil
 * @projectName mysaas
 * @description: 主表数据库连接工具类，用于执行数据库初始化及权限分配
 * @date 2022/2/12 9:06
 */
public class MasterDbUtil {
    public Connection getConnection() throws SQLException {
        MasterDatabaseConfigProperties masterDbProperties = (MasterDatabaseConfigProperties) SpringContextUtil.getBean("masterDatabaseConfigProperties");
        String url = masterDbProperties.getUrl() + "&allowMultiQueries=true";//可执行多行sql
        String username = masterDbProperties.getUsername();
        String pass = masterDbProperties.getPassword();
        DataSource ds = new SimpleDataSource(url, username, pass);
        return ds.getConnection();
    }

}
